<!--计量器具类型 -->
<script>
    import { finPageList } from '@/api/measuringType'
    import Operation from './components/Operation'
    import FormModal from './components/FormModal'
    export default {
        components: {
            Operation,
            FormModal
        },
        data() {
            return {
                name: '',
                // list: [
                //     {
                //         name: '123',
                //         code: '123',
                //         energyTypeName: '123',
                //     }
                // ],
            }
        },
        methods: {
            handleSearch(){
            this.$nextTick(() => {
                const rlTable = this.$refs.rlTable
                if(rlTable){
                    rlTable.onSearchChange()
                }
                })
            },
            loadTableData({ resolve, params }) {
                // resolve({
                //     records:this.list,
                //     total:0
                // })
                params.condition = {
                    name: this.name,
                }
                finPageList(params).then((res) => {
                    if (res.code == '200') {
                        const resData = res.data || {}
                        resolve({
                            records: resData.records || [],
                            total: resData.total,
                        })
                    } else {
                        resolve({
                            records: [],
                            total: 0,
                        })
                    }
                })
            },
            handleReset() {
                this.name = ''
                this.handleSearch()
            },
            addOnClick() {
                new this.$pageModal(
                    FormModal,
                    {
                        props: {
                            title: '新增',
                        },
                    },
                    (result) => {
                        if (result) {
                          const rlTable = this.$refs.rlTable
                          if(rlTable){
                            rlTable.onSearchChange()
                          }
                        }
                    }
                )
            },
        },
    }
</script>
<template>

    <!-- <RlTable :is-pagination="true" @on-change="loadTableData" :isShowMore="false">
        <template #default>
            <el-table-column prop="name" label="计量器具类型名称" :min-width="150" />
            <el-table-column prop="code" label="计量器具类型编码" :min-width="150" />
            <el-table-column prop="energyTypeName" label="能源类型" :min-width="150" />
            <el-table-column fixed="right" label="操作" width="200">
                <template slot-scope="scope">
                    <Operation :rowData="scope.row" />
                </template>
            </el-table-column>
        </template>
        <template #search>
            <SearchContion />
        </template>
        <template #head-left-button>
            <HeaderAction />
        </template>
    </RlTable> -->
    <div class="container">
    <div class="header">
      <el-form inline class="searchItem">
        <div style="display: flex;">
          <el-form-item label="类型名称">
              <el-input
                  v-model="name"
                  size="small"
                  placeholder="请输入类型名称"
                  style="width: 100%;"
              />
          </el-form-item>
        </div>
        <div style="display: flex;">
          <el-form-item>
              <el-button
                  size="small"
                  type="primary"
                  @click="handleSearch" 
                  icon="el-icon-search"
                  >查询</el-button
              >
              <el-button
                  size="small"
                  type="warning"
                  @click="handleReset"
                  icon="el-icon-refresh-left"
                  >重置</el-button
              >
              <el-button
                  size="small"
                  type="primary"
                  @click="addOnClick" 
                  icon="el-icon-plus"
                  >新增</el-button
              >
          </el-form-item>
        </div>
        </el-form>
    </div>
    <div class="main">
      <RlTable
          :search="false"
          :is-pagination="true"
          @on-change="loadTableData"
          ref="rlTable"
      >
          <template #default>
              <el-table-column label="序号" type="index" width="80" fixed="left" />
              <el-table-column prop="name" label="计量器具类型名称" :min-width="150" />
              <el-table-column prop="code" label="计量器具类型编码" :min-width="150" />
              <el-table-column prop="energyTypeName" label="能源类型" :min-width="150" />
              <el-table-column fixed="right" label="操作" width="200">
                  <template slot-scope="scope">
                      <Operation :rowData="scope.row" />
                  </template>
              </el-table-column>
          </template>
      </RlTable>
    </div>
  </div>
</template>

<style lang="scss" scoped>
.container {
  color: #fff;
  display: flex;
  flex-direction: column;
  width: 100%;
}
.header {
  height: 36px;
  background-color: #0C2E64;
  padding: 20px 15px;
  display: flex;
  .searchItem {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
  }
  margin-bottom: 34px;
}
.main {
  height: calc(100vh - 285px);
  position: relative;
  box-sizing: border-box;
}
::v-deep .el-form-item {
  margin-bottom: 0 !important;
  line-height: 36px !important;
  height: 36px !important;
}
::v-deep .el-form-item__label {
  line-height: 36px !important;
  height: 36px!important;
}
::v-deep .el-form-item__content {
  line-height: 36px !important;
  height: 36px !important;
}
</style>